package com.example.LibrarySystem.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.LibrarySystem.mapper.InventoryMapper;
import com.example.LibrarySystem.pojo.Inventory;
import com.example.LibrarySystem.response.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/inventory")
@Transactional
public class InventoryController {

    @Autowired
    private InventoryMapper inventoryMapper;

    @GetMapping("/{id}")
    public Result getNumberById(@PathVariable Integer id) {
        QueryWrapper<Inventory> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("book_id", id);
        Inventory inventories = inventoryMapper.selectOne(queryWrapper);
        Result result = new Result();
        if (inventories != null){
            result.setStatus(200);
            result.put("count",inventories.getNumber());
            result.setMsg("查询成功");
        }else {
            result.setStatus(-1);
            result.setMsg("查询失败");
        }
        return result;
    }
}
